home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Amiga News 95
/
Amiga News 95.iso
/
dpat
/
dpat48
/
dearch
/
sources
/
dearch.c
< prev
next >
Wrap
C/C++ Source or Header
|
1993-11-14
|
12KB
|
380 lines
/*
* DeArch.c
* Version 1.0
*/
#include <exec/types.h>
#include <exec/memory.h>
#include <exec/lists.h>
#include <dos/rdargs.h>
#include <libraries/locale.h>
#include <libraries/commodities.h>
#include <libraries/amigaguide.h>
#include <intuition/intuition.h>
#include <clib/exec_protos.h>
#include <clib/dos_protos.h>
#include <clib/locale_protos.h>
#include <clib/amigaguide_protos.h>
#include <clib/intuition_protos.h>
#include <clib/commodities_protos.h>
#ifdef __SASC
#include <pragmas/exec_pragmas.h>
#include <pragmas/dos_pragmas.h>
#include <pragmas/locale_pragmas.h>
#include <pragmas/amigaguide_pragmas.h>
#include <pragmas/intuition_pragmas.h>
#include <pragmas/commodities_pragmas.h>
#endif
#include <stdlib.h>
#define CATCOMP_NUMBERS
#include "Globals.h"
#include "CrunchPrefs.h"
#include "local_dearch.h"
#include "dearchguide.h"
#include "dearch_strings.h"
#define EV_HOTKEY 1L
#define TEMPLATE "h=?/S"
#define OPT_HELP 0
#define OPT_COUNT 1
static UBYTE *VersTag = "\0$VER: DeArch V1.0 (17.10.93)";
struct Library *LocaleBase, *AmigaGuideBase, *CxBase, *IconBase;
struct LocaleInfo li;
static struct MsgPort *cxport;
static CxObj *broker, *filter;
static struct NewBroker newbroker =
{
NB_VERSION,
"DeArch",
NULL,
NULL,
0,
COF_SHOW_HIDE, 0, 0, 0
};
static struct EasyStruct ErrorMain = {
sizeof(struct EasyStruct), 0, "DeArch",
"%s", "OK"
};
static LONG opts[OPT_COUNT];
static struct RDArgs *rdargs;
UBYTE *hotkey;
BOOL done = FALSE;
extern struct Library *IntuitionBase, *DOSBase;
extern struct List myList;
extern struct Window *ArchiveurWnd,*ArchiWnd, *PrefsWnd;
#ifdef __SASC
extern __stdargs CxObj *HotKey(STRPTR, struct MsgPort *, LONG);
extern __stdargs UBYTE **ArgArrayInit(LONG, UBYTE **);
extern __stdargs LONG ArgInt(UBYTE **, STRPTR, LONG);
extern __stdargs STRPTR ArgString(UBYTE **, STRPTR, STRPTR);
extern __stdargs void ArgArrayDone(void);
#endif
BOOL OpenLibs(void);
void CloseLibs(void);
void ProcessMsg(void);
void InitListView(void);
void KillListView(void);
void CloseAllWnd(void);
void CleanExit(void);
void main(int, char **);
void main(int argc, char **argv)
{
UBYTE **ttypes;
rdargs = ReadArgs(TEMPLATE, opts, NULL);
if (IconBase = OpenLibrary("icon.library", 37))
{
ttypes = ArgArrayInit(argc, argv);
newbroker.nb_Pri = (BYTE)ArgInt(ttypes, "CX_PRIORITY", 0);
hotkey = ArgString(ttypes, "CX_POPKEY", "control lalt d");
}
if (LocaleBase = OpenLibrary("locale.library", 38))
{
li.li_LocaleBase = LocaleBase;
li.li_Catalog = OpenCatalogA(NULL, "dearch.catalog", NULL);
if (FindPort("Dearch-Port"))
{
EasyRequest(NULL, &ErrorMain, NULL,
GetString(&li, MSG_ACTIVE));
CloseCatalog(li.li_Catalog);
CloseLibrary(LocaleBase);
if (IconBase)
{
ArgArrayDone();
CloseLibrary(IconBase);
}
if (rdargs)
FreeArgs(rdargs);
exit(0);
}
if (OpenLibs())
{
nag.nag_BaseName = "DeArch";
nag.nag_Name = "DeArch.guide";
if (opts[OPT_HELP])
if (aguide = OpenAmigaGuideA(&nag, NULL))
{
CloseAmigaGuide(aguide);
aguide = NULL;
}
InitAmigaGuide();
if (SetupScreen())
{
InitListView();
LoadPrefs();
if (OpenArchiveurWindow())
{
if (cxport = CreateMsgPort())
{
cxport->mp_Node.ln_Pri = 0;
cxport->mp_Node.ln_Name = "Dearch-Port";
AddPort(cxport);
newbroker.nb_Port = cxport;
newbroker.nb_Title = GetString(&li, MSG_COPYRIGHT);
newbroker.nb_Descr = GetString(&li, MSG_USE);
if (broker = CxBroker(&newbroker, NULL))
{
if (filter = HotKey(hotkey, cxport, EV_HOTKEY))
{
AttachCxObj(broker, filter);
if (! CxObjError(filter))
{
ActivateCxObj(broker, 1);
ProcessMsg();
}
else
EasyRequest(NULL, &ErrorMain, NULL,
GetString(&li, ERROR_MAINCOM));
}
else
EasyRequest(NULL, &ErrorMain, NULL,
GetString(&li, ERROR_MAINHOTKEY));
}
else
EasyRequest(NULL, &ErrorMain, NULL,
GetString(&li, ERROR_MAINBROKER));
}
else
EasyRequest(NULL, &ErrorMain, NULL,
GetString(&li, ERROR_MAINPORT));
}
else
EasyRequest(NULL, &ErrorMain, NULL,
GetString(&li, ERROR_MAINWIND));
}
else
EasyRequest(NULL, &ErrorMain, NULL,
GetString(&li, ERROR_MAINSETUP));
}
else
EasyRequest(NULL, &ErrorMain, NULL,
GetString(&li, ERROR_MAINLIB));
}
CleanExit();
}
void ProcessMsg(void)
{
ULONG msgid, msgtype, signals;
CxMsg *msg;
ULONG wndsigflag = 1 << ArchiveurWnd->UserPort->mp_SigBit;
ULONG cxsigflag = 1 << cxport->mp_SigBit;
ULONG archisigflag, prefssigflag;
while (!done)
{
if (ArchiWnd)
archisigflag = 1 << ArchiWnd->UserPort->mp_SigBit;
else
archisigflag = 0;
if (PrefsWnd)
prefssigflag = 1 << PrefsWnd->UserPort->mp_SigBit;
else
prefssigflag = 0;
signals = Wait(wndsigflag | archisigflag | prefssigflag | cxsigflag | amsig);
if (signals & wndsigflag)
HandleMainIDCMP();
if (signals & archisigflag)
HandleArchiIDCMP();
if (signals & prefssigflag)
HandlePrefsIDCMP();
if (signals & amsig)
HandleAmigaguide();
if (signals & cxsigflag)
{
while (msg = (CxMsg *)GetMsg(cxport))
{
msgid = CxMsgID(msg);
msgtype = CxMsgType(msg);
ReplyMsg((struct Message *)msg);
switch (msgtype)
{
case CXM_IEVENT:
if (ArchiveurWnd == NULL)
{
OpenArchiveurWindow();
wndsigflag = 1 << ArchiveurWnd->UserPort->mp_SigBit;
}
break;
case CXM_COMMAND:
switch(msgid)
{
case CXCMD_DISABLE:
ActivateCxObj(broker, 0);
break;
case CXCMD_ENABLE:
ActivateCxObj(broker, 1);
break;
case CXCMD_APPEAR:
if (ArchiveurWnd == NULL)
{
OpenArchiveurWindow();
wndsigflag = 1 << ArchiveurWnd->UserPort->mp_SigBit;
}
break;
case CXCMD_DISAPPEAR:
CloseAllWnd();
wndsigflag = archisigflag = prefssigflag = 0;
break;
case CXCMD_KILL:
done = TRUE;
break;
}
}
}
}
}
}
void CloseAllWnd(void)
{
if (ArchiveurWnd)
CloseArchiveurWindow();
if (ArchiWnd)
CloseArchiWindow();
if (PrefsWnd)
ClosePrefsWindow();
}
void InitListView(void)
{
NewList(&myList);
}
void KillListView(void)
{
struct crunch *node, *nextnode;
node = (struct crunch *)(myList.lh_Head);
while (nextnode = (struct crunch *)(node->cr_Node.ln_Succ))
{
Remove((struct Node *)node);
FreeVec(node);
node = nextnode;
}
}
void CleanExit(void)
{ CxMsg *msg;
if (broker)
DeleteCxObjAll(broker);
if (cxport)
{
while (msg = (CxMsg *)GetMsg(cxport))
ReplyMsg((struct Message *)msg);
RemPort(cxport);
DeleteMsgPort(cxport);
}
CloseAllWnd();
if (! IsListEmpty(&myList))
KillListView();
CloseDownScreen();
if (aguide)
CloseAmigaGuide(aguide);
CloseLibs();
if (IconBase)
{
ArgArrayDone();
CloseLibrary(IconBase);
}
if(rdargs)
FreeArgs(rdargs);
exit(0);
}
BOOL OpenLibs(void)
{
BOOL rc = FALSE;
if (AmigaGuideBase = OpenLibrary("amigaguide.library", 39))
if (CxBase = OpenLibrary("commodities.library", 37))
rc = TRUE;
return rc;
}
void CloseLibs(void)
{
if (LocaleBase)
{
CloseCatalog(li.li_Catalog);
CloseLibrary(LocaleBase);
}
if (AmigaGuideBase) CloseLibrary(AmigaGuideBase);
if (CxBase) CloseLibrary(CxBase);
}